package com.guyaning.deyson_ec.ec.main.sort.list;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.guyaning.deyson_core.core.ui.recycler.DataConverter;
import com.guyaning.deyson_core.core.ui.recycler.ItemType;
import com.guyaning.deyson_core.core.ui.recycler.MultipleFields;
import com.guyaning.deyson_core.core.ui.recycler.MultipleItemBean;

import java.util.ArrayList;

/**
 * Created by Administrator on 2018/6/27.
 */

public class VerticalListDataConverter extends DataConverter {

    @Override
    public ArrayList<MultipleItemBean> convert() {

        ArrayList<MultipleItemBean> beanArrayList = new ArrayList<>();

        JSONArray jsonArray = JSONArray.parseObject(getJson())
                .getJSONObject("data")
                .getJSONArray("list");

        int size = jsonArray.size();
        for (int i = 0; i < size; i++) {

            JSONObject data = jsonArray.getJSONObject(i);

            int id = data.getInteger("id");

            String name = data.getString("name");

            MultipleItemBean multipleItemBean = MultipleItemBean.builder()
                    .setField(MultipleFields.ITEM_TYPE, ItemType.VERTICAL_MENU_LIST)
                    .setField(MultipleFields.ID, id)
                    .setField(MultipleFields.TEXT, name)
                    .setField(MultipleFields.TAG, false)
                    .build();

            beanArrayList.add(multipleItemBean);

            //设置第一个被选中
            beanArrayList.get(0).setField(MultipleFields.TAG, true);

        }

        return beanArrayList;
    }
}
